package model

import (
	"fmt"
	"github.com/BurntSushi/toml"
	"path/filepath"
)

var cfg  *config

type mysql struct {
	Host     string
	User     string
	Password string
	Port     string
	Db       string
}

type jwt struct {
	Signed 	string
}

type config struct {
	Mysql mysql
	Jwt jwt
}

func ConfigLoad(path string) {
	if len(path) == 0 {
		path = "./config.toml"
	}
	filePath, err := filepath.Abs(path)
	if err != nil {
		panic(err)
	}
	fmt.Printf("parse toml file once. filePath: %s\n", filePath)
	if _, err := toml.DecodeFile(filePath, &cfg); err != nil {
		panic(err)
	}
}

func Config() *config {
	return cfg
}